<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@page import="java.net.URLDecoder"%>
<%@ page import="com.sz.common.SZUtility" %>
<%@page import="com.sz.business.bmo.IBusinessBMO"%>
<%@ page import="com.sz.common.ICommonDAO" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String business_id = SZUtility.toString(request.getParameter("business_id"));
String param = SZUtility.toString(request.getParameter("param"));

String style1 = "font-size: 12px;";
String style2 = "width: 250px";

String name = "";
String address = "";
String tel1 = "";
String avg_fee = "";
String check_contact = "";
String check_tel = "";
String check_notice = "";
String cash_mode = "";

if(!business_id.equals("")) {
	Map map = new HashMap();
	map.put("BUSINESS_ID", business_id);
	ServletContext servletContext = request.getSession().getServletContext(); 
	ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
	IBusinessBMO bmo = (IBusinessBMO)context.getBean("BusinessBMO");	
	List list = bmo.queryBusiness(map);
	if(list.size() > 0) {
		Map r = (Map)list.get(0);
		name			= SZUtility.toString(r.get("NAME"));
		address			= SZUtility.toString(r.get("ADDRESS"));
		tel1			= SZUtility.toString(r.get("TEL1"));
		avg_fee			= SZUtility.toString(r.get("AVG_FEE"));	
		check_contact	= SZUtility.toString(r.get("CHECK_CONTACT"));
		check_tel		= SZUtility.toString(r.get("CHECK_TEL"));
		check_notice 	= SZUtility.toString(r.get("CHECK_NOTICE"));
		cash_mode 		= SZUtility.toString(r.get("CASH_MODE"));			
	}
}


//left用
String left_style1 = "text-align:right;font-size: 12px;";
String left_style2 = "text-align:left;font-size:12px; width:140px";

String region_id = request.getSession().getAttribute("regionid").toString();

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ICommonDAO dao = (ICommonDAO) context.getBean("CommonDAO");

List flags = dao.getDicValueList("CHECK_FLAG");

//查到最顶级
StringBuffer buf = new StringBuffer();
buf.append("select * from region where region_level = 1 start with region_id = ");
buf.append(region_id);
buf.append(" connect by  prior parent_id =  region_id");
Map top = (Map)dao.queryForObject(buf.toString());

//自最顶级向下查
List list = new ArrayList();
if(top != null) {
	buf.delete(0, buf.length());
	buf.append("select * from region start with region_id = ");
	buf.append(top.get("REGION_ID").toString());
	buf.append(" connect by  parent_id = prior region_id");
	list = dao.queryForList(buf.toString());
}

String province_id = "";
String province_name = "";
for(int i = 0; i < list.size(); ++i) {
	Map map = (Map)list.get(i);
	if(map.get("REGION_LEVEL").toString().equals("1")) {
		province_id = map.get("REGION_ID").toString();
		province_name = map.get("REGION_NAME").toString();
		break;
	}
}

List city_list = new ArrayList();
for(int i = 0; i < list.size(); ++i) {
	Map map = (Map)list.get(i);
	if(map.get("REGION_LEVEL").toString().equals("2")) {
		city_list.add(map);
	}
}

List area_list = new ArrayList();
for(int i = 0; i < list.size(); ++i) {
	Map map = (Map)list.get(i);
	if(map.get("REGION_LEVEL").toString().equals("3")) {
		area_list.add(map);
	}
}

//根据登陆区域查商圈
buf.delete(0, buf.length());
buf.append("select * from business_group t where t.region_id in (");
buf.append("select region_id from region start with region_id = ");
buf.append(region_id);
buf.append(" connect by  parent_id = prior region_id)");
List group_list = dao.queryForList(buf.toString());
%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	<link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>">

		<title>订单核对</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="business_summary">
		<meta http-equiv="description" content="订单核对" >
		
		<style type="text/css"> 
			@import "js/tableview/TableView.css";
    	</style>
	</head>
	
	<body>
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/tableview/SortView.js"></script>
		<script type="text/javascript" src="js/tableview/PagerView.js"></script>
		<script type="text/javascript" src="js/tableview/TableView.js"></script>
		<script type="text/javascript" src="js/tableview/SelectorView.js"></script>
		<script type="text/javascript" src="js/tableview/PaperView.js"></script>
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		
	<table width="100%" height="50px" border="0" cellpadding="0" cellspacing="0">	  	 
	  	<tr>
		  	<td class="title0">订单核对</td>		  	
	  	</tr>	  	
	 </table>
	 	
	 <table style="width:100%; height:100%">
	  <tr>
	  <td style="width:260px;">	
	  <div style="width:260px; height:100%;">	   
		<form name="business_tickets_query_form" style="width: 100%" > 
	  	 <table style="width: 100%">	  	 
		  	<tr>
			  	<td style="<%=left_style1%>">省</td>
			  	<td>
			  	
			  		<select id="province" name="province" style="<%=left_style2%>" >
			  		 <option value="">请选择</option>			  		
		             <option value="<%=province_id%>" selected="selected"> <%=province_name%> </option>		             			            
			  		</select>
			  	</td>	
			</tr>
			<tr>
				<td style="<%=left_style1%>">市</td>  		
			  	<td>	
			  		<select id="city" name="city" style="<%=left_style2%>" >
			  		<option value="">请选择</option>
					 <%
					 String value;
					 String text;
					 boolean b =false;
					 for(int i = 0; i < city_list.size(); ++i) {
						Map map = (Map)city_list.get(i);
						value = map.get("REGION_ID").toString();
						text = map.get("REGION_NAME").toString();						
						if(region_id.equals(value)) b = true;  //与登陆区域相同，则选中
						if(b==false && i == city_list.size()-1) b = true;  //最后一个都还没有匹配，就默认选中
					 %>
					  <option value="<%=value%>"   <%if(b){%>selected="selected" <%}%> > 
					  <%=text%> 
					  </option>
					 <%}%> 
			  		</select>
			  	</td>
			</tr>
			<tr>
				<td style="<%=left_style1%>">区</td> 
				<td> 	
			  		<select id="area" name="area" style="<%=left_style2%>" >
			  		<option value="">请选择</option> 
			  		<%
					 for(int i = 0; i < area_list.size(); ++i) {
						Map map = (Map)area_list.get(i);
						value = map.get("REGION_ID").toString();
						text = map.get("REGION_NAME").toString();												
					 %>
					  <option value="<%=value%>"> 
					  <%=text%> 
					  </option>
					 <%} %> 
			  		</select>
			  	</td>
			</tr>  	
	
			<tr>	  	
			  	<td style="<%=left_style1%>">商圈</td>
			  	<td>
			  		<select id="group_id" name="group_id" style="<%=left_style2%>" > 
				  		<option value="">请选择</option> 
				  		<%
						 for(int i = 0; i < group_list.size(); ++i) {
							Map map = (Map)group_list.get(i);
							value = map.get("GROUP_ID").toString();
							text = map.get("NAME").toString();												
						 %>
						  <option value="<%=value%>"> 
						  <%=text%> 
						  </option>
						 <%} %> 
			  		</select>
			  	</td>
			</tr>
			
			<tr>
				<td style="<%=left_style1%>">商家ID</td>
				<td>
					<input type="text" id="b_business_id" style="<%=left_style2%>" />
				</td>	
			</tr>
			<tr>
				<td style="<%=left_style1%>">商家名称</td>
				<td>
					<input type="text" id="b_name" style="<%=left_style2%>" />
				</td>	
			</tr>
			<tr>
				<td style="<%=left_style1%>">首拼</td>
				<td>
					<input type="text" id="py" style="<%=left_style2%>" />
				</td>	
			</tr>
			
			<tr>
				<td style="<%=left_style1%>">商家核单</td>
				<td>
					<select id="check_b_flag" name="check_b_flag" style="<%=left_style2%>">
						<option value="">全部</option>
					   <%
					   String check_flag_value = null;
					   String check_flag_text = null;
					   boolean default_b = false;
					   %>
					   
					   <%
					   for(int n = 0; n < flags.size(); ++n) { 
						   
						   Map tmp = (Map)flags.get(n);
						   check_flag_value = tmp.get("DIC_VALUE").toString();
						   check_flag_text = tmp.get("DIC_TEXT").toString();
						   default_b = check_flag_value.toString().equals("0");
					   %>
					   <option <%if(default_b){%> selected="selected" <%}%>
					     value="<%=check_flag_value%>"><%=check_flag_text%>
					   </option>
					   <%}%>
					</select>	 
				</td>	
			</tr>
			<tr>
				<td style="<%=left_style1%>">客户核单</td>
				<td>
					<select id="check_c_flag" name="check_c_flag" style="<%=left_style2%>">
						<option value="">全部</option>
					   <%
					   check_flag_value = null;
					   check_flag_text = null;
					   default_b = false;
					   %>
					   
					   <%
					   for(int n = 0; n < flags.size(); ++n) { 
						   
						   Map tmp = (Map)flags.get(n);
						   check_flag_value = tmp.get("DIC_VALUE").toString();
						   check_flag_text = tmp.get("DIC_TEXT").toString();
						   default_b = check_flag_value.toString().equals("0");
					   %>
					   <option <%if(default_b){%> selected="selected" <%}%>
					     value="<%=check_flag_value%>"><%=check_flag_text%>
					   </option>
					   <%}%>
					</select>	 
				</td>	
			</tr>
			
			<!-- 下单时间  -->
			<tr>
				<td style="<%=left_style1%>">下单时间</td>
			  	<td>
			  		<input type="text" id="create_time_d_begin" name="create_time_d_begin" readonly="readonly" style="width: 80px;" onclick="calendar.show(this)" >
			  		<select id="create_time_t_begin" name="create_time_t_begin" style="width: 56px; display:none;" >
			  		  <option selected="selected"></option>
			  		  <%
					  for(int n = 0; n < 24; ++n) {
						  
						  value = String.valueOf(n);
						  text = value + "时";
					  %>
					  <option 
					    value="<%=value%>"><%=text%>
					  </option>
					  <%}%>				   
			  		</select>
			  		<font style="font-size: 12px;">至</font>
			  	</td>	
			</tr>
			<tr>
				<td style="<%=left_style1%>"></td>
				<td>
					<input type="text" id="create_time_d_end" name="create_time_d_end" readonly="readonly" style="width: 80px;" onclick="calendar.show(this)" >
			  		<select id="create_time_t_end" name="create_time_t_end" style="width: 56px; display:none;" >
			  		  <option selected="selected"></option>
			  		  <%
					  for(int n = 0; n < 24; ++n) {
						  
						  value = String.valueOf(n);
						  text = value + "时";
					  %>
					  <option 
					    value="<%=value%>"><%=text%>
					  </option>
					  <%}%>				   
			  		</select>
			  	</td>	
			</tr>
			
			<!-- 预约时间  -->
			<tr>
				<td style="<%=left_style1%>">预约时间</td>
			  	<td>
			  		<input type="text" id="demand_time_d_begin" name="demand_time_d_begin" readonly="readonly" style="width: 80px;" onclick="calendar.show(this)" >
			  		<select id="demand_time_t_begin" name="demand_time_t_begin" style="width: 56px; display:none;" >
			  		  <option selected="selected"></option>
			  		  <%
					  for(int n = 0; n < 24; ++n) {
						  
						  value = String.valueOf(n);
						  text = value + "时";
					  %>
					  <option 
					    value="<%=value%>"><%=text%>
					  </option>
					  <%}%>				   
			  		</select>
			  		<font style="font-size: 12px;">至</font>		  					  		
			  	</td>
			</tr>
			<tr>
				<td style="<%=left_style1%>"></td>
				<td>
					<input type="text" id="demand_time_d_end" name="demand_time_d_end" readonly="readonly" style="width: 80px;" onclick="calendar.show(this)" >
			  		<select id="demand_time_t_end" name="demand_time_t_end" style="width: 56px; display:none;" >
			  		  <option selected="selected"></option>
			  		  <%
					  for(int n = 0; n < 24; ++n) {
						  
						  value = String.valueOf(n);
						  text = value + "时";
					  %>
					  <option 
					    value="<%=value%>"><%=text%>
					  </option>
					  <%}%>				   
			  		</select>
				</td>
			</tr>
			
			<tr style="display: none;">
				<td style="<%=left_style1%>">商家核单操作员</td>
				<td>
					<input type="text" id="check_b_manager" style="<%=left_style2%>" />
				</td>	
			</tr>
			<tr style="display: none;">
				<td style="<%=left_style1%>">客户核单操作员</td>
				<td>
					<input type="text" id="check_c_manager" style="<%=left_style2%>" />
				</td>	
			</tr>
			
			<tr>
				<td colspan="2">
					<input type="button" value="查询" onclick="onQueryBusinessTickets()"/>
					<input type="button" value="导出" onclick="onExportAllTickets()"/>					
				</td>
			</tr>					
	  	</table>	  	
  	   </form>		
	  </div>
	  </td>
		
		<!--  
	  	 <table width="100%" border="0" cellpadding="0" cellspacing="0">
	  	 
	  	 <tr>
	  	 	<th colspan="8" align="left">商家信息</th>	  	 	
	  	 </tr>
	  	 
	  	 <tr>	  	 	
	  	 	<td style="<%=style1%>">名称&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="name" readonly="readonly" value="<%=name%>" >
	  	 	</td>
	  	 	
	  	 	<td style="<%=style1%>">地址&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="address" readonly="readonly" value="<%=address%>" >
	  	 	</td>
	  	 	
	  	 	<td style="<%=style1%>">订餐电话&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="tel1" readonly="readonly" value="<%=tel1%>" >
	  	 	</td>
	  	 	
	  	 	<td style="<%=style1%>">人均消费&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="avg_fee" value="<%=avg_fee %>" readonly="readonly" />
	  	 	</td>
	  	 </tr>
	  	 <tr>	  	 	
	  	 	<td style="<%=style1%>">核单人&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="check_contact" readonly="readonly" value="<%=check_contact%>" >
	  	 	</td>
	  	 	
	  	 	<td style="<%=style1%>">核单人电话&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="check_tel" readonly="readonly" value="<%=check_tel%>" >
	  	 	</td>
	  	 	
	  	 	<td style="<%=style1%>">核单注意事项&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="check_notice" readonly="readonly" value="<%=check_notice%>" >
	  	 	</td>
	  	 	
	  	 	<td style="<%=style1%>">结算模式&nbsp;</td>
	  	 	<td>
	  	 		<input type="text" id="cash_mode" value="<%=cash_mode %>" readonly="readonly" />
	  	 	</td>
	  	 </tr>	  	  			 	
	  	</table>
	  	-->
	  	
	  	<td>
	  	<div align="left" style="width:100%;height:100%">
	  		<div id="left_table_div" style= "width: 100%"></div>
			<div id="left_pager"></div>
		  	<table border="0" cellpadding="0" cellspacing="0">
		  		<tr>
		  			<td align="center">
		  				<input type="button" value="查询订单" onclick="onQueryBusinessTicketList()" style="width: 80px">&nbsp;&nbsp;
		  				<input type="button" value="导出订单" onclick="onExportTickets()" style="width: 80px">&nbsp;&nbsp;&nbsp;&nbsp;		  				
		  				<input type="button" value="预占商家" onclick="onLockBusiness(1)" style="width: 80px">&nbsp;&nbsp;
		  				<input type="button" value="释放商家" onclick="onLockBusiness(0)" style="width: 80px">
		  			</td>
		  		</tr>
		  	</table>
		
			<br/>
			<input type="text" id="select_tip" readonly="readonly" style="border:none; width:100%; color: red;" />
			<div id="table_div" style= "width: 100%" align="left"></div>
			<div id="pager" align="left"></div>	
		</div>
		</td>
		</tr>
		</table>
		
		<form name="export_form"  action="ticket/exportTicket.exec" method="post"> 
		  <input type="hidden" id="PARAM_VALUE" name="PARAM_VALUE">
		  <input type="hidden" id="TITLE_FIELD" name="TITLE_FIELD">
		  <input type="hidden" id="BUSINESS_ID_LIST" name="BUSINESS_ID_LIST"> <!--选择几个商家导出使用 -->
		</form>
	
  	<SCRIPT LANGUAGE="JavaScript">
  	
  		var numPerPage = 10; //每页行数
		var paramValue = "<%=param%>";
		var methodCount = "queryTicketCount";
		var methodPage = "queryTicketPage";
		
		var table = new TableView('table_div');
		table.header = {
			TICKET_ID			: '订单编号',			
			CUST_TEL			: '客户电话',
			CUST_NAME			: '客户姓名',
			CREATE_TIME_STR		: '下单时间',
			DEMAND_TIME_STR		: '预约时间',
			CHECK_B_FLAG_STR	: '商家核单',
			CHECK_C_FLAG_STR	: '客户核单',
			CHECK_B_OPERATE		: '商家',
			CHECK_C_OPERATE		: '客户'
		};		
		table.customDefine = {
			TICKET_ID			: 'style= "display: none;"',			
			CUST_TEL			: '',
			CUST_NAME			: '',
			CREATE_TIME_STR		: '',
			DEMAND_TIME_STR		: '',
			CHECK_B_FLAG_STR	: '',
			CHECK_C_FLAG_STR	: '',
			CHECK_B_OPERATE		: '',
			CHECK_C_OPERATE		: ''			
		};
				
		table.dataKey = 'TICKET_ID';
		table.display.marker = false;
		table.display.multiple = false;
		table.display.count = false;
		table.title = false;
		table.display.filter = false;
		table.display.pager = false;
		table.display.multiple = false;
		table.pager.size = numPerPage;		

		var pager = new PagerView('pager');
		pager.onclick = onPagerClick;
		pager.itemCount = 0;
		pager.size = numPerPage;
		
		table.render();
		pager.render();

		function queryTicket(pageNO, returnCount) {
  	  		var begin = (pageNO-1) * numPerPage + 1;
  	  		var end = pageNO * numPerPage;
  	  		var mc = returnCount==true ? methodCount : "";
  	  		var date = {
  	  			BEAN_METHOD 	: "TicketBMO.queryTicket",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: paramValue,
  	    	  	METHOD_COUNT 	: mc, //为空则不返回记录数
  	    	  	METHOD_PAGE 	: methodPage, //为空则不分页
  	    	  	PAGE_BEGIN 		: begin, //仅在METHOD_PAGE不为空时使用
  	    	  	PAGE_END 		: end
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: query_success,
				error: show_error
  	  		});
  	  	}
  	  	
  	  	function onPagerClick(pageNO) {
  			queryTicket(pageNO, "FLASE");
  		}
  	  	
  	  	//刷新当前页
  		function refreshCurrentPage() {
  			queryTicket(pager.index, "FLASE");
  		}
  			
  		function onQueryTicket() {
  			if(paramValue != null && paramValue != "") {  		
	  			pager.index = 1;
	  	  		queryTicket(1, true);
  	  		}
  		}
  		
  		function query_success(data) {
  	  		var jdata = eval("(" + data + ")");
  	  		if(jdata.COUNT != null) { //有记录数返回  	  	  		
  	  	  		pager.itemCount = jdata.COUNT;
  	  	  		pager.size = numPerPage;  	  	  		
  	  	  		pager.render();
  	  		} 
		   var array = eval(jdata.LIST);
		   for(var i = 0; i < array.length; ++i) {		   		
		   		var url = "<input type=\"button\" value=\"核单\" onclick=\"onCheck_B('";
		   		url += array[i].TICKET_ID;
		   		url += "')\">";
		   		array[i].CHECK_B_OPERATE = url;
		   		
		   		var url = "<input type=\"button\" value=\"核单\" onclick=\"onCheck_C('";
		   		url += array[i].TICKET_ID;
		   		url += "')\">";
		   		array[i].CHECK_C_OPERATE = url;
		   		
		   		if(array[i].CHECK_B_FLAG == "1") array[i].CHECK_B_FLAG_STR="已消费";
		   		else if(array[i].CHECK_B_FLAG == "0") array[i].CHECK_B_FLAG_STR="待核单";
		   		else if(array[i].CHECK_B_FLAG == "-1") array[i].CHECK_B_FLAG_STR="未消费";
		   		
		   		if(array[i].CHECK_C_FLAG == "1") array[i].CHECK_C_FLAG_STR="已消费";
		   		else if(array[i].CHECK_C_FLAG == "0") array[i].CHECK_C_FLAG_STR="待核单";
		   		else if(array[i].CHECK_C_FLAG == "-1") array[i].CHECK_C_FLAG_STR="未消费";
		   		
		   }		  
		   table.clear();
		   table.addRange(array);
		}
  		function show_error(data) {
  			var err = "操作失败！\n";
  			err += "status：" + data.status + "\n";
  			err += "statusText：" + data.statusText;
  	  		alert(err);
 		}
 		function onCheck_B(ticket_id) {
 			var row = table.get(ticket_id);
 			if(row.CHECK_B_FLAG != "0") {
 				if(window.confirm("商家已经核单，确认要继续吗?") == false) return;
 			}
 			
 			var url = "<%=path%>";
  			url += "/ticket/checkTicket_Business.page?ticket_id=" + ticket_id;
  			url += "&final_callback=queryTicketForUpdate("+ticket_id+")"; //按目前的逻辑，成功后会转到“操作成功”的界面，在“操作成功”的界面回调这个函数刷新
  			  						
  			var param = "status:no;scroll:no;dialogWidth:1024px;dialogHeight:700px";
			//window.showModalDialog(url, window, param);
			//queryTicketForUpdate(ticket_id);
			
			var width = 1024; //弹出窗口的宽度;
			var height = 700; //弹出窗口的高度;
			var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
			var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
			var style = "toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no";			
			window.open (url,"商家核单","height="+height+",width="+width+",top="+top+",left="+left+","+style);
			
 			
 		}
 		function onCheck_C(ticket_id) {
 			var row = table.get(ticket_id);
 			if(row.CHECK_C_FLAG != "0") {
 				if(window.confirm("客户已经核单，确认要继续吗?") == false) return;
 			}
 			
 			var url = "<%=path%>";
  			url += "/ticket/checkTicket_Custom.page?ticket_id=" + ticket_id;
  			url += "&final_callback=queryTicketForUpdate("+ticket_id+")"; //按目前的逻辑，成功后会转到“操作成功”的界面，在“操作成功”的界面回调这个函数刷新
  			  						
  			var param = "status:no;scroll:no;dialogWidth:1024px;dialogHeight:700px";
			//window.showModalDialog(url, window, param);
			//queryTicketForUpdate(ticket_id);
			
			var width = 1024; //弹出窗口的宽度;
			var height = 700; //弹出窗口的高度;
			var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
			var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
			var style = "toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no";			
			window.open (url,"客户核单","height="+height+",width="+width+",top="+top+",left="+left+","+style);
			
 		}
 		
 		function queryTicketForUpdate(ticket_id) {
 			var param = "{";			
			param += " TICKET_ID:'" + ticket_id;
			param += "'";			
			param += "}"
			
  	  		var date = {
  	  			BEAN_METHOD 	: "TicketBMO.queryTicket",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: param,
  	    	  	METHOD_COUNT 	: "", //为空则不返回记录数
  	    	  	METHOD_PAGE 	: "" //为空则不分页  	    	  
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: updateTable,
				error: show_error
  	  		});
  	  	}
  	  	function updateTable(data) {
  	  		var jdata = eval("(" + data + ")"); 
		    var array = eval(jdata.LIST);
		    if(array.length == 0) return;
		    
		    var v = array[0];
		    //与query_success一致
		    var url = "<input type=\"button\" value=\"核单\" onclick=\"onCheck_B('";
	   		url += v.TICKET_ID;
	   		url += "')\">";
	   		v.CHECK_B_OPERATE = url;
	   		
	   		var url = "<input type=\"button\" value=\"核单\" onclick=\"onCheck_C('";
	   		url += v.TICKET_ID;
	   		url += "')\">";
	   		v.CHECK_C_OPERATE = url;
	   		
	   		if(v.CHECK_B_FLAG == "1") v.CHECK_B_FLAG_STR="已消费";
	   		else if(v.CHECK_B_FLAG == "0") v.CHECK_B_FLAG_STR="待核单";
	   		else if(v.CHECK_B_FLAG == "-1") v.CHECK_B_FLAG_STR="未消费";
	   		
	   		if(v.CHECK_C_FLAG == "1") v.CHECK_C_FLAG_STR="已消费";
	   		else if(v.CHECK_C_FLAG == "0") v.CHECK_C_FLAG_STR="待核单";
	   		else if(v.CHECK_C_FLAG == "-1") v.CHECK_C_FLAG_STR="未消费";
		  
		   		
		    var row = table.get(v.TICKET_ID);
		    if(row != null && row != false) {
		    	//row = v;  //直接赋值不行啊。。。
		    	//目前只能写死了
		    	
		    	row.CHECK_B_FLAG = v.CHECK_B_FLAG;
		    	row.CHECK_C_FLAG = v.CHECK_C_FLAG;
		    	row.CHECK_B_FLAG_STR = v.CHECK_B_FLAG_STR;
		    	row.CHECK_C_FLAG_STR = v.CHECK_C_FLAG_STR;
		    	table.render();
		    }
  	  	}
  	  	function onLockBusiness(lockflag) {
  	  		var id = "";
  			var rows = left_table.getSelected(); // Array[Object]
  			if(rows.length != 1) {
  				alert("请选择一个商家");
  				return;
  			}
  			id = rows[0].BUSINESS_ID;
  			if(id == null || id == "") {
  				alert("参数错误");
  				return;
  			}
  			
  			var callback = "";
  			if(lockflag == 1) {
  				callback = lock_success;
  			} else if(lockflag == 0) {
  				callback = release_success
  			}
  			
  	  		var date = {
  	  			OPERATE_TYPE	: "LOCK",
  	  			BUSINESS_ID 	: id,
  	  			LOCKFLAG		: lockflag
  	  			
  	  	    };
  	  	    
  	  		$.ajax({
				type: "POST",
				url: "lockBusiness.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: callback,
				error: show_error
  	  		});
  	  	}
  	  	   		
  		function lock_success(data) {
  			release_success(data);
  			
  			//预占后就查询
  			onQueryBusinessTicketList();
  		}
  		function release_success(data) {
  			alert(data);
  			
  			//取当前选择
  			var id = "";
  			var rows = left_table.getSelected(); // Array[Object]
  			if(rows.length == 1) {
  				queryForUpdateLock(rows[0].BUSINESS_ID);  				
  			}
  		}
  		
  		function queryForUpdateLock(business_id) {
 			var param = "{";			
			param += " BUSINESS_ID:'" + business_id;
			param += "'";			
			param += "}"
			
  	  		var date = {
  	  			BEAN_METHOD 	: "BusinessBMO.queryBusinessInfo",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: param,
  	    	  	METHOD_COUNT 	: "", //为空则不返回记录数
  	    	  	METHOD_PAGE 	: "" //为空则不分页  	    	  
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: updateBusinessLock,
				error: show_error
  	  		});
  	  	}
  	  	function updateBusinessLock(data) {
  	  		var jdata = eval("(" + data + ")"); 
		    var array = eval(jdata.LIST);
		    if(array.length == 0) return;
		    
		    var v = array[0];
  	  		var row = left_table.get(v.BUSINESS_ID);
		    if(row != null && row != false) {
		    	row.LOCK_MANAGER_NAME = v.LOCK_MANAGER_NAME;
		    	left_table.render();
		    	
		    	//选中
		    	for(var i = 0; i < left_table.rows.length; ++i) {
		    		if(left_table.rows[i].BUSINESS_ID == v.BUSINESS_ID) {
		    			$(left_table.container).find('td.marker input')[i].checked = "checked";		    			
		    			break;
		    		}
		    	}
		        
		    }
  	  	}
  		//left
  		var left_numPerPage = 10; //每页行数
		var left_paramValue = "";
		var left_methodCount = "queryBusinessTicketsCount";
		var left_methodPage = "queryBusinessTicketsPage";
		
		var left_table = new TableView('left_table_div');
		left_table.header = {
			BUSINESS_ID			: '商家编号',
			NAME				: '商家名称',
			TEL1				: '预约电话',
			ADDRESS				: '商家地址',
			AVG_FEE				: '人均消费',
			CHECK_CONTACT		: '核单联系人',
			CHECK_TEL			: '核单电话',
			CHECK_NOTICE		: '核单注意事项',
			LOCK_MANAGER_NAME	: '预占人',
			TICKET_COUNT		: '订单数目'
			
			
		};		
		left_table.customDefine = {
			BUSINESS_ID			: '',
			NAME				: '',
			TEL1				: '',
			ADDRESS				: '',
			AVG_FEE				: '',
			CHECK_CONTACT		: '',
			CHECK_TEL			: '',
			CHECK_NOTICE		: '',
			LOCK_MANAGER_NAME	: '',
			TICKET_COUNT		: ''
		};
				
		left_table.dataKey = 'BUSINESS_ID';				
		left_table.display.count = false;
		left_table.title = false;
		left_table.display.filter = false;
		left_table.display.pager = false;
		left_table.dblclick = onClickTable;		

		var left_pager = new PagerView('left_pager');
		left_pager.onclick = onPagerClick;
		left_pager.itemCount = 0;
		left_pager.size = left_numPerPage;
		
		left_table.render();
		left_pager.render();

		function queryBusinessTickets(pageNO, returnCount) {
  	  		var begin = (pageNO-1) * left_numPerPage + 1;
  	  		var end = pageNO * left_numPerPage;
  	  		var mc = returnCount==true ? left_methodCount : "";
  	  		var date = {
  	  			BEAN_METHOD 	: "TicketBMO.queryBusinessTickets",
  	  			PARAM_CLASS 	: "java.util.Map",
  	    	  	PARAM_VALUE 	: left_paramValue,
  	    	  	METHOD_COUNT 	: mc, //为空则不返回记录数
  	    	  	METHOD_PAGE 	: left_methodPage, //为空则不分页
  	    	  	PAGE_BEGIN 		: begin, //仅在METHOD_PAGE不为空时使用
  	    	  	PAGE_END 		: end
  	  	    };
  	  		$.ajax({
				type: "POST",
				url: "query.exec",
				//data: {id:'123'},
				data: date,
				datatype:"json",
				success: left_query_success,
				error: left_show_error
  	  		});
  	  	}
  	  	
  	  	function onPagerClick(pageNO) {
  			queryBusinessTickets(pageNO, "FLASE");
  		}
  	  	
  	  	//刷新当前页
  		function left_refreshCurrentPage() {
  			queryBusinessTickets(pager.index, "FLASE");
  		}
  			
  		function onQueryBusinessTickets() {
  			//先检查输入  			
  			
  			var region_id = "";
  			var province = document.getElementById("province").value;
  			var city = document.getElementById("city").value;
  			var area = document.getElementById("area").value;
  			
  			if(area != null && area != "") {
  				region_id = area;
  			} else if(city != null && city != "") {
  				region_id = city;
  			} else {
  				region_id = province;
  			}
  			
  			//默认取登陆的
  			if(region_id == null || region_id == "") {
  				region_id = "<%=region_id%>"
  			}
  			
  			//生成查询参数paramValue
  			var tmp;
			left_paramValue = "{";
			
			left_paramValue += " STATUS:'" + 99;
			left_paramValue += "'";
			left_paramValue += ",";
			
			left_paramValue += " B_REGION_ID:'" + region_id;  //按目前的逻辑，region_id一直不为空
			left_paramValue += "'";
			left_paramValue += ",";
			
  			tmp = document.getElementById("group_id").value;
  			left_paramValue += " B_GROUP_ID:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";
			
			tmp = document.getElementById("b_business_id").value;
			tmp = jQuery.trim(tmp);
			if(tmp!="" && IsInteger(tmp)==false) {
				alert("请正确输入商家ID，只能为数字");
				return;
			}
  			left_paramValue += " B_BUSINESS_ID:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";
			
			tmp = document.getElementById("b_name").value;
  			left_paramValue += " B_NAME:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";
			
			tmp = document.getElementById("py").value.toUpperCase();
  			left_paramValue += " BUSINESS_CODE:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";
			
			tmp = document.getElementById("check_b_flag").value;
  			left_paramValue += " CHECK_B_FLAG:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ","; 
			
			tmp = document.getElementById("check_c_flag").value;
  			left_paramValue += " CHECK_C_FLAG:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";	
			
			//下单时间
			tmp = document.getElementById("create_time_d_begin").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("create_time_t_begin").value;
				if(t == null || t == "") t="0"; //开始时间默认最小0
				
				tmp += " "+t;
			} */  //屏蔽 只按天查
			left_paramValue += " CREATE_TIME_BEGIN:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";
			
			tmp = document.getElementById("create_time_d_end").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("create_time_t_end").value;
				if(t == null || t == "") t="23"; //结束时间默认最大23
				
				tmp += " "+t;
			}*/ //屏蔽 只按天查
			left_paramValue += " CREATE_TIME_END:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";
			
			//预约时间
			tmp = document.getElementById("demand_time_d_begin").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("demand_time_t_begin").value;
				if(t == null || t == "") t="0"; //开始时间默认最小0
				
				tmp += " "+t;
			}*/
			left_paramValue += " DEMAND_TIME_BEGIN:'" + tmp;
			left_paramValue += "'";
			left_paramValue += ",";
			
			tmp = document.getElementById("demand_time_d_end").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("demand_time_t_end").value;
				if(t == null || t == "") t="23"; //结束时间默认最大23
				
				tmp += " "+t;
			}*/
			left_paramValue += " DEMAND_TIME_END:'" + tmp;
			left_paramValue += "'";					    			
  			  			
  			left_paramValue += "}";  			
  			
  			//若上述发生更改，记得改下面的onClickTable
  			
  			pager.index = 1;
  	  		queryBusinessTickets(1, true);
  		}
  		
  		function left_query_success(data) {
  	  		var jdata = eval("(" + data + ")");
  	  		if(jdata.COUNT != null) { //有记录数返回  	  	  		
  	  	  		left_pager.itemCount = jdata.COUNT;
  	  	  		left_pager.size = left_numPerPage;  	  	  		
  	  	  		left_pager.render();
  	  		} 
		   var array = eval(jdata.LIST);		  
		   left_table.clear();
		   left_table.addRange(array);
		}
  		function left_show_error(data) {
  			var err = "操作失败！\n";
  			err += "status：" + data.status + "\n";
  			err += "statusText：" + data.statusText;
  	  		alert(err);
 		} 		
  	
  		function onClickTable(id) {
  						
  		}
  		
  		function generateBusinessTicketParam(type) {
  			//type 为 "query" 或 "export"
  			//区别是：query只有一个business_id, export可以有多个
  			//目前，只用了query，export未用
  			
  			var id = "";
  			var rows = left_table.getSelected(); // Array[Object]
  			if(rows.length == 0) {
  				alert("请选择商家");
  				return null;
  			}
  			
  			if(type == "query") {
	  			if(rows.length != 1) {
	  				alert("请选择一个商家");
	  				return null;
	  			}
	  			id = rows[0].BUSINESS_ID;
  			} else { //export
  				for(var i = 0; i < rows.length; ++i) {
  					id += rows[i].BUSINESS_ID;
  					if(i < rows.length-1) id += ",";
  				}  				
  			}
  			
  			if(id == null || id == "") {
  				alert("参数错误");
  				return null;
  			}
  			
  			document.getElementById("select_tip").value = "  当前选择的商家：" + rows[0].NAME;
  			
  			var region_id = "";
  			var province = document.getElementById("province").value;
  			var city = document.getElementById("city").value;
  			var area = document.getElementById("area").value;
  			
  			if(area != null && area != "") {
  				region_id = area;
  			} else if(city != null && city != "") {
  				region_id = city;
  			} else {
  				region_id = province;
  			}
  			
  			//默认取登陆的
  			if(region_id == null || region_id == "") {
  				region_id = "<%=region_id%>"
  			}
  			
  			//生成查询参数paramValue
  			var tmp;
			var tmp_paramValue = "{";
			
			tmp_paramValue += " STATUS:'" + 99;
			tmp_paramValue += "'";
			tmp_paramValue += ",";			
			
  			tmp_paramValue += " BUSINESS_ID:'" + id;
			tmp_paramValue += "'";
			tmp_paramValue += ",";			
			
			tmp = document.getElementById("check_b_flag").value;
  			tmp_paramValue += " CHECK_B_FLAG:'" + tmp;
			tmp_paramValue += "'";
			tmp_paramValue += ","; 
			
			tmp = document.getElementById("check_c_flag").value;
  			tmp_paramValue += " CHECK_C_FLAG:'" + tmp;
			tmp_paramValue += "'";
			tmp_paramValue += ","; 
			
			//下单时间
			tmp = document.getElementById("create_time_d_begin").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("create_time_t_begin").value;
				if(t == null || t == "") t="0"; //开始时间默认最小0
				
				tmp += " "+t;
			}*/ //屏蔽 只按天查
			tmp_paramValue += " CREATE_TIME_BEGIN:'" + tmp;
			tmp_paramValue += "'";
			tmp_paramValue += ",";
			
			tmp = document.getElementById("create_time_d_end").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("create_time_t_end").value;
				if(t == null || t == "") t="23"; //结束时间默认最大23
				
				tmp += " "+t;
			}*/ //屏蔽 只按天查
			tmp_paramValue += " CREATE_TIME_END:'" + tmp;
			tmp_paramValue += "'";
			tmp_paramValue += ",";
			
			//预约时间
			tmp = document.getElementById("demand_time_d_begin").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("demand_time_t_begin").value;
				if(t == null || t == "") t="0"; //开始时间默认最小0
				
				tmp += " "+t;
			}*/
			tmp_paramValue += " DEMAND_TIME_BEGIN:'" + tmp;
			tmp_paramValue += "'";
			tmp_paramValue += ",";
			
			tmp = document.getElementById("demand_time_d_end").value;
			/*if(tmp != null && tmp != "") {
				var t = document.getElementById("demand_time_t_end").value;
				if(t == null || t == "") t="23"; //结束时间默认最大23
				
				tmp += " "+t;
			}*/
			tmp_paramValue += " DEMAND_TIME_END:'" + tmp;
			tmp_paramValue += "'";				    			
  			  			
  			tmp_paramValue += "}";
  			
  			return tmp_paramValue;
  		}
  		
  		function onQueryBusinessTicketList() {
  			
  			var tmp_paramValue = generateBusinessTicketParam("query");
  			if(tmp_paramValue == null) return;  			
  			
  			paramValue = tmp_paramValue; //右侧的查询 使用paramValue值 
  			onQueryTicket();
  		}
  		
  		function getTitleField() {
  		    var v = '商家编号:BUSINESS_ID,商家名称:B_NAME,商家电话:B_TEL,核单注意事项:B_NOTICE,签约状态:B_CHECK_STATUS,';
  			v += '客户姓名:CUST_NAME,客户电话:CUST_TEL,就餐时间:DEMAND_TIME_STR,预订要求:DEMAND_STR,预订结果:BUSINESS_RESPONSE,';
  			v += '预订桌数:DEMAND_NUM,预订人数:STAFF_NUM,商家核单桌数:CHECK_B_NUMBER,客户核单桌数:CHECK_C_NUMBER,商家核单人数:CHECK_B_STAFFNUM,';
  			v += '客户核单人数:CHECK_C_STAFFNUM,商家核单消费金额:CHECK_B_TOTAL,客户核单消费金额:CHECK_C_TOTAL,商家核单结果:CHECK_B_FLAG_STR,商家核单操作员:CHECK_B_MANAGER,';
  			v += '商家核单操作员工号:CHECK_B_MANAGER_NAME,就餐环境:CHECK_B_ENV,包间/桌号:CHECK_B_POSITION,客户核单结果:CHECK_C_FLAG_STR,客户核单操作员:CHECK_C_MANAGER,';
  			v += '客户核单操作员工号:CHECK_C_MANAGER_NAME,商家核单人:CHECK_B_CONTACT,下单操作员:CREATE_MANAGER,下单操作人工号:CREATE_MANAGER_NAME,';
  			v += '备注:COMMENT_TEXT';
  			
  			return v;  		
  		}
  		
  		function onExportAllTickets() {
  			if(left_paramValue == "") return;  			
  			var v = getTitleField();
  			
  	  	    document.getElementById("PARAM_VALUE").value = left_paramValue;  //使用left_paramValue
  	  	    document.getElementById("TITLE_FIELD").value = v;
  	  	    document.getElementById("BUSINESS_ID_LIST").value = ""; //注意导出所有的，要清空这个
			document.getElementById("export_form").submit();
  		}
  		
  		//导出选择的商家的订单
  		function onExportTickets() {
  			if(left_paramValue == "") return;  			
  			var v = getTitleField();

			var id = "";
  			var rows = left_table.getSelected(); // Array[Object]
  			if(rows.length == 0) {
  				alert("请选择商家");
  				return;
  			}  
			for(var i = 0; i < rows.length; ++i) {
				id += rows[i].BUSINESS_ID;
				if(i < rows.length-1) id += ",";
			}
  			
  			if(id == null || id == "") {
  				alert("参数错误");
  				return;
  			}
  			
  	  	    document.getElementById("PARAM_VALUE").value = left_paramValue;
  	  	    document.getElementById("TITLE_FIELD").value = v;  	
  	  	    document.getElementById("BUSINESS_ID_LIST").value = id;	    
			document.getElementById("export_form").submit();
  		}
  	 </SCRIPT>
	
	</body>
</html>
